<?php
class BookDHController extends BaseController{

	function IndexAction(){
	$obj = ModelFactory::M('BookDHModel');
		// $data1 = $obj->GetAllBookDH();	//是一个二维数组
		$data2 = $obj->GetCount();	//是一个数字
		//获取页码
		$page=isset($_GET['page'])?$_GET['page']:1;
		//设定每页显示的数据量
		$length=3;
		//求出分页偏移量
		$offset=($page-1)*$length;
		//总页数
		$pages=ceil($data2/$length);
		//求出上一页和下一页对应的页码
		$prev=$page>1?$page-1:1;
		$next=$page<$pages?$page+1:$pages;

		$data1 = $obj->GetAllBookDH($offset,$length);	//是一个二维数组
		//载入视图文件，以显示该2份数据：
		include VIEW_PATH . 'book_dh_list.html';
	}
	function ShowAllBookDHAction(){
		$obj = ModelFactory::M('BookDHModel');
		$data1 = $obj->GetAllBookDH();	//是一个二维数组
		//$data2 = $obj->GetUserCount();	//是一个数字
		//载入视图文件，以显示该2份数据：
		include VIEW_PATH . 'book_dh_list.html';
	}
	//添加图书--数据提交
	function AddBookDHAction(){
		//接收表单数据：
		$DGH = $_POST['DGH'];
		$SDJG = $_POST['SDJG'];
		$SDCS = $_POST['SDCS'];
		$DHRQ = $_POST['DHRQ'];
		$JSRZGH = $_POST['JSRZGH'];
		$BZ = $_POST['BZ'];
		
		$obj = ModelFactory::M('BookDHModel');
		$result = $obj->InsertBookDH($DGH, $SDJG,$SDCS,$DHRQ, $JSRZGH,$BZ);
		$this->GotoUrl('添加到货图书成功！', '?c=BookDH&a=Index', 3 );
	}
	//添加新到货的图书界面
	function ShowFormAction()
	{
		include VIEW_PATH . 'book_dh_add.html';
	}
	function DelAction(){
		$dh_id = $_GET['dh_id'];
		$obj = ModelFactory::M('BookDHModel');
		$result = $obj->delBookDHById($dh_id);
		$this->GotoUrl('删除成功！', '?c=BookDH&a=Index', 6 );
	}
	function DetailAction(){
		//获取一个用户的信息
		$dh_id = $_GET['dh_id'];
		$obj = ModelFactory::M('BookDHModel');
		$data = $obj->GetBookDHInfoById($dh_id);

		//显示到“一个用户的视图”中
		include VIEW_PATH . 'book_dh_info.html';
	}
	function EditAction(){
		$dh_id = $_GET['dh_id'];
		//从数据库中取出该用户的所有数据信息：
		$obj = ModelFactory::M('BookDHModel');
		$book = $obj->GetBookDHInfoById($dh_id);
		//兴趣数据，需要单独处理
		
		include VIEW_PATH . 'book_dh_edit.html';
	}
	function UpdateBookDHAction(){
		//接收表单数据：
		$dh_id = $_POST['dh_id'];
		$DGH = $_POST['DGH'];
		$SDJG = $_POST['SDJG'];
		$SDCS = $_POST['SDCS'];
		$DHRQ = $_POST['DHRQ'];


		$JSRZGH = $_POST['JSRZGH'];
		$BZ = $_POST['BZ'];
		$obj = ModelFactory::M('BookDHModel');
		$result = $obj->UpdateBookDH($dh_id,$DGH, $SDJG,$SDCS,$DHRQ, $JSRZGH,$BZ);
		$this->GotoUrl('修改订购图书成功！', '?c=BookDH&a=Index', 3 );
	}
	
}
